#! /usr/bin/perl -w
###############################################################################
# author : Mike Rolland , rmk677@gmail.com                                    #
###############################################################################
#  Thanks to Muhammad Muquit, http://www.muquit.com/ for his uploader model   #
###############################################################################
### ask for commiter priviledge if you want to upload files to the project  ###
###############################################################################
use utf8;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/;
#use Gtk2::Pango;
use Gtk2::WebKit;

## WARNING, IF MARBLE ISN'T IN YOUR APP PATH, IT WONT APPEAR IN CYC MENU ##
# dir & user list
### CHANGE ME ###
######## LOCAL DATA #########
$user = "/home/mike";
$dirs = "$user/Documents/CLIM";
$svn_dirs = "$user/Dev/svn";
######### USER_IDs ##########
## google pass : ask owner ##
## to be allowed to commit ##
$g_user = "rmk677";
$g_pass = "";
######## PROJECT_IDs ########
$g_project = "h-track";
$g_svn = "$svn_dirs/$g_project"; $g_svn =~ s/\n//g;
#############################
$sat = "$dirs/daily_sat";
$arch = "$dirs/archive";
######## LOCALIZATION #######
$LOCALE = "indian";
# commande list
#my ($command1,$command2,$command3,$command4,$command5,$command6,$command7,$command8);
$command1 = ('h_track -p'); # check ponctually area
$command2 = ('h_track -i'); # dl and view last sat image (eog)
$command3 = ('h_track -k'); #check cron state
$command4 = ('h_track -c'); # start cron check
$command5 = ('h_track -di'); # dl sat image daily in background
$command6 = ('h_track -hi'); # dl sat image hourly in background
$command7 = ('h_track -s'); # stop and remove user cron file
$command8 = ('h_track -r'); # reset html data if download error

$rep1 = ("nautilus $dirs");
$rep2 = ("nautilus $sat");
$rep3 = ("nautilus $arch");

$app1 = ("marble");

$tmp = "$user/.TMP";
$tempmsg0 = ("$user/.MSG.txt");
$tempmsg1 = ("$user/.MSG1.txt");
$tempmsg2 = ("$user/.MSG2.txt");
$stormlog = ("$dirs/storm.log");
$imagelog = ("$dirs/.image.log");
# Variable
my ($button01,$button02,$button03,$button04,$button05,$button06,$button07,$button08,$button09,$button10,
   $button11,$button12,$button13,$button14,$button15,$button16,$button17,$button18,$button19,$button20,
   $button21,$button22,$button23,$button24,$button25,$buttonX
   );
my ($urf,$urlX,$urlsafe,$url1,$url2,$url3,$url4,$url5,$url6,$url7,$url8,$url9,$url10,
   $url11,$url12,$url13,$url14,$url15,$url16,$url17,$url18,$url19,$url20,$url21,$url22,$url23,
   );
my ($utc,$utn,$uta,$utat,$utp,$gmt,$heure,$min,$jour,$jourtext,$mois,$moistext,$an,$year,
   $fulldate,$short,$log_date,$storm,$lat,$lon,$kml_file,
   );

   $heure = (`date +%H`);
   $min = (`date +%M`);
   $jour = (`date +%d`);
   $jourtext = (`date +%A`);
   $mois = (`date +%m`);
   $moistext = (`date +%B`);
   $an = (`date +%Y`);
   $year = (`date +%y`);
   $utc = &utc_time;
   $gmt = (`date +%:::z`);
   $short = (`date +%d/%m`);
   $fulldate = (`date +%A\\,\\ %d\\ %B\\ %Y.`);
   $log_date = (`cat $stormlog|cut -d \',\' -f1|sed -n \'s\/\\([0-9]\\{2\\}\\)\/\\1 \/;\$p\'|awk \'\{print \$2\"\/\"\$1\}\'`);

my $point = "RÉUNION";

if ($stormlog ne "") {
	$storm = (`cat "$stormlog"\|cut -d \',\' -f5\|sed -n \'\$p\'`);
}
else {
	$storm = "Le Bassin";
}
if ( -d "$dirs/kml/") {
	$kml_file = "$dirs/kml/$storm.kml";
	$kml_file =~ s/\n//g;
}
print $kml_file;
sub utc_time {
	$utc = (`date -u +%H`);
	if (($utc ge "00")&&($utc le "05")){$uta = '0000';$utat = '00H00';$utp = '18H00';$utn = '06H00';}
	if (($utc ge "06")&&($utc le "11")){$uta = '0600';$utat = '06H00';$utp = '00H00';$utn = '12H00';}
	if (($utc ge "12")&&($utc le "17")){$uta = '1200';$utat = '12H00';$utp = '06H00';$utn = '18H00';}
	if (($utc ge "18")&&($utc le "23")){$uta = '1800';$utat = '18H00';$utp = '12H00';$utn = '00H00';}
}


# Data
	# Info cyclone
	$com01 = "Contrôle de la Zone";
	$com02 = "Télécharger Image satellite";
	#$com03 = "Voir dernier message";
	$com04 = "Rapport journalier";
	$com05 = "Voir info cyclone globale"; # url13
	
	# navigation locale
	$browse01 = "Dossier Principal";
	$browse02 = "Dossier Satellite";
	$browse03 = "Dossier Archives";
	$browse04 = "Transert sur SVN (manuel)";
	$browse05 = "Archivage sur Serveur";
	# tache de fond
	$button01 = "Démarrage du timer";
	$com06 = "État du timer";
	$button02 = "Image satellite journalière";
	$button03 = "Image satellite horaire";
	$button04 = "Arrêt du timer";
	$button05 = "Reset fichier temporaire";
	# meteo locale
	$button06 = "Bulletin du jour"; # url1
	$button07 = "Prévvision matin"; # url2
	$button08 = "Prévision apres-midi"; # url3
	$button09 = "Pression de surface"; # url6
	$button10 = "Info mensuelle générale"; # url7
	$button11 = "Images radar (Réunion)"; # url4
	$button12 = "Images satellite (Réunion)"; # url5
	# Documents Ocean Indien
	$button13 = "Météo Marine (oceanweather)"; # ulr14
	$button14 = "Image vapeur d'eau (globale $LOCALE)"; # url8
	$button15 = "Image Infre-rouge (globale $LOCALE)"; # url9
	$button16 = "Image Infra-rouge (dundee)"; # url10
	$button17 = "Image Micro-onde (dundee)"; # url11
	$button18 = "Image Vapeur d'eau (dundee)"; # url12
	# Documents Techniques
	$button19 = "Pression au niveau de la mer"; # url15
	$button20 = "Température, humidité et vent"; # url16
	$button21 = "Potentiel d'énergie et précipitation "; # url17
	$button22 = "Potentiel Vortex et Altitude"; # url18
	$button23 = "Accélération verticale"; # url19
	$button24 = "Ligne de courant et Isotachs"; # url20
	$button25 = "Aide pour l'analyses des cartes"; # url21
	# button de test
	$buttonX = "Info test"; # urlX

	# meteo reunion
	$url1 = "http://www.meteo.fr/temps/domtom/La_Reunion/meteoreunion2/previsions/bulletin/index.html" ;
	$url2 = "http://www.meteo.fr/temps/domtom/La_Reunion/meteoreunion2/previsions/matin/index.html" ;
	$url3 = "http://www.meteo.fr/temps/domtom/La_Reunion/meteoreunion2/previsions/apres_midi/index.html" ;
	$url4 = "http://www.meteo.fr/temps/domtom/La_Reunion/meteoreunion2/observations/radar/images_radar/index.html";
	$url5 = "http://www.meteo.fr/temps/domtom/La_Reunion/meteoreunion2/observations/satellite/images_sat/index.html";
	$url6 = "http://www.weatheronline.co.uk/daten/sailcharts/gfs/$an/$mois/$jour/pslv_afri_00.gif";
	$url7 = "http://www.meteo.fr/temps/domtom/La_Reunion/Evenement_du_mois/image002.gif";
	# satellite globale
	#$url8 = "http://cimss.ssec.wisc.edu/tropic/real-time/indian/images/xxirmet5bbm.jpg";
	$url8 = "http://tropic.ssec.wisc.edu/real-time/imagemain.php?&basin=$LOCALE&prod=wvbbm&sat=m5";
	#$url9 = "http://cimss.ssec.wisc.edu/tropic/real-time/indian/images/xxirmet5n.GIF";
	$url9 = "http://tropic.ssec.wisc.edu/real-time/imagemain.php?&basin=$LOCALE&prod=irbbm&sat=m5";
	# dundee image globale
	$url10 = "http://www.sat.dundee.ac.uk/geobrowse/geobrowse.php?sat=1&year=$an&month=$mois&day=$jour&slot=$uta&ch=2&size=2&grid=1";
	$url11 = "http://www.sat.dundee.ac.uk/geobrowse/geobrowse.php?sat=1&year=$an&month=$mois&day=$jour&slot=$uta&ch=3&size=2&grid=1";
	$url12 = "http://www.sat.dundee.ac.uk/geobrowse/geobrowse.php?sat=1&year=$an&month=$mois&day=$jour&slot=$uta&ch=3&size=2&grid=1";
	# info cyclone générale
	$url13 = "http://www.meteo.fr/marine/naviweb/bms/BMS_CYCLONES.html";
	# meteo marine (Nord Indien)
	$url14 = "http://www.oceanweather.com/data/Indian-Northern/index.html";
	# documents techniques meteo
	$url15 = "http://wxmaps.org/pix/af2.00hr.png"; # Pression au niveau de la mer & couche (1000-500mb)
	$url16 = "http://wxmaps.org/pix/af4.00hr.png"; # Temperature,humidité et vent (800Mo)
	$url17 = "http://wxmaps.org/pix/af6.00hr.png"; # Potentiel d'energie disponible et précipitation'
	$url18 = "http://wxmaps.org/pix/af1.00hr.png"; # hauteur et vortex potentiel (500mb)
	$url19 = "http://wxmaps.org/pix/af3.00hr.png"; # Velocité verticale (700mb)
	$url20 = "http://wxmaps.org/pix/af5.00hr.png"; # Ligne de courant et Isotachs (200mb)
	$url21 = "file:$dirs/guide_analyses.html"; # aide analyses cartes
	# données googlemaops (upload vers my maps)
	$url22 = "http://maps.google.fr/";
	$url23 = "http://tropic.ssec.wisc.edu/tropic.php";

	$urlsafe = $url1; # 'http://google.com';


my $window = Gtk2::Window->new ('toplevel');
$window->set_title("H tracker");
$window->set_size_request (850,);
$window->signal_connect (delete_event => sub { Gtk2->main_quit });
my $mainbox = &ret_mainbox();
$window->add ($mainbox);
$window->show;
Gtk2->main ();

# vbox,frame,border,addvbox
sub ret_mainbox {
	my $mainbox = Gtk2::VBox->new(0,0);
	my $scrollwin = Gtk2::ScrolledWindow->new;
	$scrollwin->set_policy ('automatic', 'automatic');
	$scrollwin->set_size_request (840,580);
	$mainbox->set_border_width(3);
	$cadre = Gtk2::Table->new(8, 2, FALSE);
	#$cadre->set_size_request(800,600);
	#$mainbox->add($cadre);
	$scrollwin->add_with_viewport($cadre);
	$mainbox->pack_start($scrollwin,FALSE,FALSE,0);

	# meteo locale
	my $meteo_box = &meteo_data();
	$cadre->attach_defaults($meteo_frame,0,1,0,1);

	# info cyclone
	my $cyc_box = &info_cyc();
	$cadre->attach_defaults($cyc_frame,0,1,1,2);

	# Documents Ocean Indien
	my $doc_box = &image_doc_data();
	$cadre->attach_defaults($doc_frame,0,1,2,3);

	# Documents Techniques
	my $tech_box = &tech_doc_data();
	$cadre->attach_defaults($tech_frame,0,1,3,4);

	# navigation dossiers
	my $data_box = &ret_data();
	$cadre->attach_defaults($data_frame,0,1,4,5);

	# message de sortie
	my $messagebox = &msg_frame();
	$cadre->attach_defaults($messageframe,0,1,5,6);

	# taches de fonds
	my $back_box = &ret_background();
	#$cadre->attach_defaults($back_frame,0,1,6,7);
	$cadre->attach_defaults($back_frame,0,1,6,7);

	# bouton de sortie
	my $exit_box = &ret_exit();
	$cadre->attach_defaults($exit_frame,0,1,7,8);

	# navigateur web
	my $netbox = &net_branch();
	$cadre->attach_defaults($net_frame,1,2,0,8);

	# info web
	#my $optional_box = &option_box();
	#$cadre->attach_defaults($optional_frame,1,2,7,8);

	$mainbox->show_all();
	return $mainbox;

	sub ret_exit {
		my $exit_box = Gtk2::VBox->new(0,0);
		$exit_frame = Gtk2::Frame->new();
		$exit_frame->set_border_width(5);
		$exit_frame->add($exit_box);
		$exit_button = Gtk2::Button->new_from_stock('gtk-close');
		$exit_button->set_border_width(3);
		$exit_button->signal_connect (clicked=>sub {
		Gtk2->main_quit;
		});
		$exit_box->pack_start($exit_button,FALSE,FALSE,0);
	}
	sub info_cyc {
		# button 1
		#my $cyc_box = Gtk2::VBox->new(0,0);
		#$box1->set_size_request(200,);
		$cyc_frame = Gtk2::Frame->new();
		$cyc_frame->set_border_width(4);

		# button : voir 'date'>'Info cyclone'

		$cyc_scroll = Gtk2::ComboBox->new_text;
		$cyc_scroll->set_border_width(3);
		$cyc_scroll->set_size_request((220,30));
		$cyc_scroll->append_text("Informations Cyclone");

		$cyc_scroll->append_text($com04);
		$cyc_scroll->append_text($com01);
		#$cyc_scroll->append_text($com03);
		$cyc_scroll->append_text($com02);
		$cyc_scroll->append_text($com05);
		#$cyc_scroll->append_text($com06);
		$cyc_scroll->signal_connect('changed'=>\&cyc_bt);
		$cyc_scroll->set_active(0);
		#if ((`find /usr/bin/ -iname "$app1"`) ne ""){
		#	$com02b = "Ouvrir Marble";
		#	$cyc_scroll->append_text($com02b);
		#	$cyc_scroll->signal_connect('changed'=> sub {
		#		if(($cyc_scroll->get_active_text) eq $com02b){
		#			$cyc_scroll->get_active;
		#			$cyc_scroll->get_active_text;
		#			system ($app1);
		#		}
		#	});
		#}
		$cyc_frame->add($cyc_scroll);

		sub cyc_bt {
		my ($cyc_scroll) = @_;
		if($cyc_scroll->get_active){
			if(($cyc_scroll->get_active_text) eq $com01 ){
				system ($command1);
				#$advisory = $tempmsg2;
				if ($tempmsg2){
					if (`cat "$tempmsg2"` ne ""){
					$advisory = "$tempmsg2";
					}
				}
				else {
				$advisory = "$tempmsg1";
				}
				&msgbox1;
				}
			if(($cyc_scroll->get_active_text) eq $com02 ){
				system ($command2);
				my $sat_img = (`cat "$imagelog"\|cut -d \'\,\' -f2\|sed -n \'\$p\'`);
				#my $sat_img = (`echo -e "$imagelog"\|sed -n \'s\/\^\.\*\\/\/\/\;\$p\'`);
				#$urf = (`find "$sat" -iname "sat_img"`);
				$PAGE = "file:$sat_img";
				&activate_uri;
				}
			#if(($cyc_scroll->get_active_text) eq $com03 ){
			#	$advisory = $tempmsg1;
			#	&msgbox1;
			#	}
			if(($cyc_scroll->get_active_text) eq $com04 ){
				$advisory = $tempmsg2;
				$lat = (`cat "$stormlog"\|cut -d \',\' -f6\|sed -n \'\$p\'`);
				$lon = (`cat "$stormlog"\|cut -d \',\' -f7\|sed -n \'\$p\'`);
				if (`cat "$advisory"` eq ""){
				$advisory = "$tempmsg1";
				}
				&msgbox4;
				}
			if(($cyc_scroll->get_active_text) eq $com05 ){
				$PAGE = $url13;
				&activate_uri;
				}
			#if(($cyc_scroll->get_active_text) eq $com06 ){
			#	system ($command3);
			#	$advisory = $tempmsg0;
			#	&msgbox1;
			#	}
			}
		}
	}
	sub ret_background {
		#my $scroll
		#my $back_box = Gtk2::VBox->new(0,0);
		$back_frame = Gtk2::Frame->new();
		$back_frame->set_border_width(4);

		$back_scroll = Gtk2::ComboBox->new_text;
		$back_scroll->set_border_width(3);
		$back_scroll->set_size_request((220,30));
		$back_scroll->append_text("Taches de Fonds");

		# button : voir 'data'>'tachesde fond'

		$back_scroll->append_text($button01);
		$back_scroll->append_text($com06);
		$back_scroll->append_text($button02);
		$back_scroll->append_text($button03);
		$back_scroll->append_text($button04);
		$back_scroll->append_text($button05);
		#$scroll->append_text($button8);
		$back_scroll->signal_connect('changed'=>\&back_bt);
		$back_scroll->set_active(0);
		$back_frame->add($back_scroll);
		#$back_box->add($back_scroll);

		sub back_bt {
		my ($back_scroll) = @_;
		if($back_scroll->get_active){
			if(($back_scroll->get_active_text) eq $button01 ){
				system ($command4);
				}
			if(($back_scroll->get_active_text) eq $button02 ){
				system ($command5);
				}
			if(($back_scroll->get_active_text) eq $button03 ){
				system ($command6);
				}
			if(($back_scroll->get_active_text) eq $button04 ){
				system ($command7);
				}
			if(($back_scroll->get_active_text) eq $button05 ){
				system ($command8);
				}
			if(($back_scroll->get_active_text) eq $com06 ){
				system ($command3);
				$advisory = $tempmsg0;
				&msgbox1;
				}
			}
		}
	}
	sub ret_data {

		my $data_box = Gtk2::VBox->new(0,0);
		$data_frame = Gtk2::Frame->new();
		$data_frame->set_border_width(4);

		$data_scroll = Gtk2::ComboBox->new_text;
		$data_scroll->set_border_width(3);
		$data_scroll->set_size_request((220,30));
		$data_scroll->append_text("Gestion des donnees");

		$data_scroll->append_text($browse01);
		$data_scroll->append_text($browse02);
		$data_scroll->append_text($browse03);
		#$kml_file = "$dirs/kml/$storm.kml";
		#$kml_file =~ s/\n//g;
		if ( -f $kml_file ) {
			$data_scroll->append_text($browse04);
			if ( -d $g_svn ) {
			$data_scroll->append_text($browse05);
			}
		}
		if ((`find /usr/bin/ -iname "$app1"`) ne ""){
			$com02b = "Ouvrir Marble";
			$back_scroll->append_text($com02b);
			$back_scroll->signal_connect('changed'=> sub {
				if(($back_scroll->get_active_text) eq $com02b){
					$back_scroll->get_active;
					$back_scroll->get_active_text;
					system ($app1);
				}
			});
		}
		$data_scroll->signal_connect('changed'=>\&data_bt);
		$data_scroll->set_active(0);

		$data_frame->add($data_scroll);
		sub data_bt {
		my ($data_scroll) = @_;
		if($data_scroll->get_active){
			if(($data_scroll->get_active_text) eq $browse01 ){
				system ($rep1);
				}
			if(($data_scroll->get_active_text) eq $browse02 ){
				system ($rep2);
				}
			if(($data_scroll->get_active_text) eq $browse03 ){
				system ($rep3);
				}
			if(($data_scroll->get_active_text) eq $browse04 ){
				$data_scroll->get_active;
				$data_scroll->get_active_text;
				&upload_pre_ops;
				&svn_upload;
			}
			if(($data_scroll->get_active_text) eq $browse05 ){
				$data_scroll->get_active;
				$data_scroll->get_active_text;
				&upload_pre_ops;
				&archive_upload;
			}
			#if(($data_scroll->get_active_text) eq $browse04 ){
			#	$PAGE = $url22;
			#	&activate_uri;;
			#	}

		}
		}
	}
	sub meteo_data {
		#my $meteo_box = Gtk2::VBox->new(0,0);

		# voir: 'data'>'meteo locale'

		$meteo_frame = Gtk2::Frame->new();
		$meteo_frame->set_border_width(4);
		$scroll_meteo = Gtk2::ComboBox->new_text;
		$scroll_meteo->set_border_width(3);
		$scroll_meteo->set_size_request((220,30));
		$scroll_meteo->append_text("Meteo locale");
		$scroll_meteo->signal_connect('changed'=>\&meteo_bt);

		$scroll_meteo->append_text($button06);
		$scroll_meteo->append_text($button07);
		$scroll_meteo->append_text($button08);
		$scroll_meteo->append_text($button09);
		$scroll_meteo->append_text($button10);
		$scroll_meteo->append_text($button11);
		$scroll_meteo->append_text($button12);

		$scroll_meteo->set_active(0);
		$meteo_frame->add($scroll_meteo);

		sub meteo_bt {
		my ($scroll_meteo) = @_;
		if($scroll_meteo->get_active){
			if(($scroll_meteo->get_active_text) eq $button06 ){
				  $PAGE = $url1;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $button07 ){
				  $PAGE = $url2;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $button08 ){
				  $PAGE = $url3;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $button09 ){
				  $PAGE = $url6;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $button10 ){
				  $PAGE = $url7;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $button11 ){
				  $PAGE = $url4;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $button12 ){
				  $PAGE = $url5;
				  &activate_uri;
				}
			if(($scroll_meteo->get_active_text) eq $buttonX ){
				#$image = (`cat "$imagelog"\|cut -d \',\' -f2\|sed -n \'\$p\'\|sed -n \'s\/\^\\\/\/\/p\'`);
				#$urf = "file:$sat/$image";
				#  $PAGE = $urf;
				#  &activate_uri;
				}
			}

		}
	}
	sub image_doc_data {
		#my $doc_box = Gtk2::VBox->new(0,0);

		# voir: 'data'>'documents ocean indien'

		$doc_frame = Gtk2::Frame->new();
		$doc_frame->set_border_width(4);
		$scroll_doc = Gtk2::ComboBox->new_text;
		$scroll_doc->set_border_width(3);
		$scroll_doc->set_size_request((220,30));
		$scroll_doc->append_text("Docmuents Zone Ocean Indien");
		$scroll_doc->signal_connect('changed'=>\&doc_bt);

		$scroll_doc->append_text($button13);
		$scroll_doc->append_text($button14);
		$scroll_doc->append_text($button15);
		$scroll_doc->append_text($button16);
		$scroll_doc->append_text($button17);
		$scroll_doc->append_text($button18);
		$scroll_doc->append_text($buttonX);

		$scroll_doc->set_active(0);
		$doc_frame->add($scroll_doc);

		sub doc_bt {
		my ($scroll_doc) = @_;
		if($scroll_doc->get_active){
			if(($scroll_doc->get_active_text) eq $button13 ){
				  $PAGE = $url14;
				  &activate_uri;
				}
			if(($scroll_doc->get_active_text) eq $button14 ){
				  $PAGE = $url8;
				  &activate_uri;
				}
			if(($scroll_doc->get_active_text) eq $button15 ){
				  $PAGE = $url9;
				  &activate_uri;
				}
			if(($scroll_doc->get_active_text) eq $button16 ){
				  $PAGE = $url10;
				  &activate_uri;
				}
			if(($scroll_doc->get_active_text) eq $button17 ){
				  $PAGE = $url11;
				  &activate_uri;
				}
			if(($scroll_doc->get_active_text) eq $button18 ){
				  $PAGE = $url12;
				  &activate_uri;
				}
			if(($scroll_doc->get_active_text) eq $buttonX ){
				  $PAGE = "/home/mike/Documents/CLIM/daily_sat/11-03/0303-1602.jpg";
				  &activate_uri;
				}
		}
		}
	}
	sub tech_doc_data {
		#my $tech_box = Gtk2::VBox->new(0,0);

		# voir: 'data'>'documents techniques'

		$tech_frame = Gtk2::Frame->new();
		$tech_frame->set_border_width(4);
		$scroll_tech = Gtk2::ComboBox->new_text;
		$scroll_tech->set_border_width(3);
		$scroll_tech->set_size_request((220,30));
		$scroll_tech->append_text("Documents Techniques");
		$scroll_tech->signal_connect('changed'=>\&tech_bt);

		$scroll_tech->append_text($button19);
		$scroll_tech->append_text($button20);
		$scroll_tech->append_text($button21);
		$scroll_tech->append_text($button22);
		$scroll_tech->append_text($button23);
		$scroll_tech->append_text($button24);
		$scroll_tech->append_text($button25);

		$scroll_tech->set_active(0);
		$tech_frame->add($scroll_tech);

		sub tech_bt {
		my ($scroll_tech) = @_;
		if($scroll_tech->get_active){
			if(($scroll_tech->get_active_text) eq $button19 ){
				  $PAGE = $url15;
				  &activate_uri;
				}
			if(($scroll_tech->get_active_text) eq $button20 ){
				  $PAGE = $url16;
				  &activate_uri;
				}
			if(($scroll_tech->get_active_text) eq $button21 ){
				  $PAGE = $url17;
				  &activate_uri;
				}
			if(($scroll_tech->get_active_text) eq $button22 ){
				  $PAGE = $url18;
				  &activate_uri;
				}
			if(($scroll_tech->get_active_text) eq $button23 ){
				  $PAGE = $url19;
				  &activate_uri;
				}
			if(($scroll_tech->get_active_text) eq $button24 ){
				  $PAGE = $url20;
				  &activate_uri;
				}
			if(($scroll_tech->get_active_text) eq $button25 ){
				  $PAGE = $url21;
				  &activate_uri;
				}
			}

		}
	}
	sub net_branch {
	my $netbox = Gtk2::VBox->new(0,0);
	   $netbox->set_border_width(2);
	   $net_frame = Gtk2::Frame->new("Navigateur Meteo");
	   $net_frame->set_border_width(10);
	   $net_frame->add($netbox);
	   #$mainbox->pack_start($net_frame,1,1,1);

	my $toolbarbox = Gtk2::VBox->new(FALSE,0);
	   $toolbarbox->set_border_width(2);
	   my $toolbar = Gtk2::Toolbar->new;
	   $toolbar->set_icon_size ('small-toolbar');
	   $toolbar->set_show_arrow (FALSE);
	   $toolbar->set_orientation ('GTK_ORIENTATION_HORIZONTAL');

	   #make the toolbar buttons, etc
	   my $button01 = Gtk2::ToolButton->new_from_stock('gtk-go-back');
	   $button01->signal_connect( "clicked" => \&go_back, undef );
	   $toolbar->insert($button01, -1);
	   $toolbar->insert(Gtk2::SeparatorToolItem->new ,-1 );

	   $button02 = Gtk2::ToolButton->new_from_stock('gtk-go-forward');
	   $button02->signal_connect( "clicked" => \&go_forward, undef );
	   $toolbar->insert($button02, -1);
	   $toolbar->insert(Gtk2::SeparatorToolItem->new ,-1 );

	   $button03 = Gtk2::ToolButton->new_from_stock('gtk-ok');
	   $button03->signal_connect( "clicked" => sub {
	    $PAGE = $url1;
	    &activate_uri;
	    });
	   $toolbar->insert($button03, -1);
	$toolbarbox->pack_start($toolbar,FALSE,FALSE,0);
	$netbox->pack_start($toolbarbox,1,1,1);;

	my $viewbox = Gtk2::VBox->new(FALSE,0);
	   $viewbox->set_border_width(2);
	   my $scroll = Gtk2::ScrolledWindow->new;
	   $scroll->set_policy ('automatic', 'automatic');
	   $scroll->set_size_request (500, 450);
	   $webox = Gtk2::WebKit::WebView->new;
	   $webox->signal_connect( 'hovering-over-link' => \&hovering_link, undef );
	   $webox->signal_connect( 'notify::load-status' => \&notification, undef );
	   &activate_uri;
	   $scroll->add($webox);
	   $viewbox->pack_start($scroll,1,1,0);
	   $netbox->pack_start($viewbox,1,1,1);
	$webox->grab_focus;

	my $option_bar = Gtk2::VBox->new();
	$statusbar = Gtk2::Statusbar->new;
	$statusbar->set_size_request((220,30));
	$status_context_id = $statusbar->get_context_id('Link Hover');
	$netbox->pack_start($statusbar,FALSE,FALSE,0);

	sub go_back{ $webox->go_back }
	sub go_forward{ $webox->go_forward }

	sub activate_uri{
		$URI = $PAGE;
		if ($URI ne "" ){
		$uri = $URI;
		#$uri ||= $URI;
		}
		else {
		#$uri = $entry->get_text;
		$uri ||= $urlsafe;
		}
		#$uri ||= $url1;
		$webox->open( $ARGV[0] || $uri );
		#$webox->load_uri($uri);
		#return->$mainbox;
	}

	sub notification{
		if( $webox->get('load_status') eq 'WEBKIT_LOAD_COMMITTED'){
			my $note_frame = $webox->get_main_frame();
			my $uri = $webox->frame_get_uri($note_frame);
			#if( $uri ){ $uri }
		}
}
	sub hovering_link{
		my ($hash, undef, $link) = @_;

		if(defined $link){
		#print "$status_context_id\t$link \n";
		$statusbar->pop($status_context_id);
		$statusbar->push($status_context_id, $link);
		}
}
	#$mainbox->show_all;
	#$mainbox->add($netbox);
	}
	sub msg_frame {
		my $messagebox = Gtk2::VBox->new(0,0);
		$messagetitle = "MESSAGE DU JOUR";
		$messageframe = Gtk2::Frame->new($messagetitle);
		my $messagetext = &msgbox3;
		$messageframe->set_border_width(5);


	}
	sub msg_frame0 {
		my $messagebox = Gtk2::VBox->new(0,0);
		$messagetitle = "MESSAGE DU JOUR";
		$messageframe = Gtk2::EventBox->new($messagetitle);
		my $messagetext = &msgbox3;
		$messageframe->set_border_width(5);


	}
	sub option_box {
		my $optional_box = Gtk2::VBox->new(0,0);
		$optional_frame = Gtk2::Frame->new("option");
		$optional_frame->set_size_request(200,80);
		$optional_frame->set_border_width(5);
		$optional_frame->add($optional_box);
	}
	sub msgbox1 {
		#$advisory = "$tempmsg";

		my $msgtype = (`cat -n "$advisory"|awk \'\{print \$1\}\'\|sed -n \'\$p\'`);
		# NoWarning popup ()
		if ($msgtype le '5'){
			#my $txttitle= (`cat "$advisory"\|sed -n \'1p\'\|sed -n \'s\/é\/e\/g\;s\/\[à\|â\]\/a\/g\;p\'`);
			my $txttitle= (`cat "$advisory"\|sed -n \'1p\'`);
			#my $txtfield = (`cat "$advisory"\|sed -n \'2\,5p\'\|sed -n \'s\/é\/e\/g\;s\/\[à\|â\]\/a\/g\;p\'`);
			my $txtfield = (`cat "$advisory"\|sed -n \'2\,5p\'`);
			$txttitle =~ s/Ã©/é/g;$txttitle =~ s/Ã/à/g;$txttitle =~ s/Ã¢/â/g;
			$txtfield =~ s/Ã©/é/g;$txtfield =~ s/Ã/à/g;
			$label1 = "\n<span foreground='yellow' size='large'>$txttitle</span>";
			$label2 = "\n<span size='large'>$txtfield</span>";
			if ($txtfield ne ""){
				$span = "$label1$label2";
			}
			else {
				$span = "$label1";
			}
			$yesno = 'close';
		}
		# Warning popup (500,300)
		elsif($msgtype gt '5'){
			my $txttitle = (`cat "$advisory"\|sed -n \'1p\'`);
			my $txtadvisory = (`cat "$advisory"\|sed -n \'2p\'`);
			my $txtfield = (`cat "$advisory"\|sed -n \'3\,7p\'`);
			my $txtwarning = (`cat "$advisory"\|sed -n \'8p\'`);
			$txttitle =~ s/Ã©/é/g;$txttitle =~ s/Ã/à/g;$txttitle =~ s/Ã¢/â/g;
			$txtfield =~ s/Ã©/é/g;$txtfield =~ s/Ã/à/g;
			$label1 = "\n<span foreground='yellow' size='x-large'>$txttitle</span>\n";
			$label2 = "\n<span foreground='orange' weight='bold' size='large'>$txtadvisory</span>\n";
			$label3 = "\n<span size='large'>$txtfield</span>";
			$label4 = "\n<span foreground='green' weight='bold' size='large'>$txtwarning</span>\n";
			$label5 = "\n<span weight='bold' size='medium'>Consulter l'image satellite ?</span>";
			if ($txtwarning ne ""){
				$span = "$label1$label2$label3$label4$label5";
			}
			$yesno = 'yes-no';
		}
		my $txt = (); # (`echo -e \""$txttitle"\\n"$txtfield"\\n"$txtwarning""`);
		my $msg = Gtk2::MessageDialog->new_with_markup($window,
			[qw/modal destroy-with-parent/],
			'warning',
			$yesno,
			$txt);
		$msg->set_markup("$span");
		$msg->set_size_request(490);
		$msg->set_border_width(5);
		$yes = $msg->run;
		if ($yes eq 'yes'){
			system ($command2);
			$image = (`cat "$imagelog"\|cut -d \',\' -f2\|sed -n \'\$p\'`);
			$urf = "file:$sat/$image`";
			$PAGE = $urf;
			&activate_uri;
			$msg->destroy;
		}
		else{
			$msg->destroy;
		}
	}
	sub time_reader {
		&utc_time;
		## $utc "00" à "05" -> $uta = '0000' > $utat = '00H00' > $utp = '18H00' > $utn = '06H00'
		## $utc "06" à "11" -> $uta = '0600' > $utat = '06H00' > $utp = '00H00' > $utn = '12H00'
		## $utc "12" à "17" -> $uta = '1200' > $utat = '12H00' > $utp = '06H00' > $utn = '18H00'
		## $utc "18" à "23" -> $uta = '1800' > $utat = '18H00' > $utp = '12H00' > $utn = '00H00'
		if ($uta eq '0') {
			$uta = "00";
		}
		else {
			$uta =~ s/0//g;
		}
		$actual_time = ($uta + $gmt);
		#$previous_time = ($actual_time - 6);
		#$previous_u = ($utn - 6);
		$next_u = ($uta + 6);
		if ($next_u ge '24') {
			$next_time = ($actual_time +6 - 24); #print ("A$actual_time, $utn, $next_time A");
			$next_u = "00";
		}
		else {
			$next_time = ($actual_time + 6); #print ("B $actual_time, $utn, $next_time B");
		}
	}
	sub msgbox2 {
		my $info_text = ($filed);
		my $form = "<span foreground='yellow' size='11000'>$filed</span>";
		my $info = Gtk2::MessageDialog->new_with_markup($window,
			[qw/modal destroy-with-parent/],
			'warning',
			'close',
			$info_text);
		$info->set_markup("$form");
		$info->set_size_request(490);
		$info->set_border_width(5);
		$info->run;
		$info->destroy;
	}
	sub msgbox3 {
		if (`cat "$tempmsg2"` ne ""){
		$advisory = "$tempmsg2";
		}
		else {
		$advisory = "$tempmsg1";
		}
		my $month_in = "\U$moistext";
		$storm = "\U$storm";
		#print $day_in;
		#$month_in =~ s/(é|è)/E/g;
		#$month_in =~ s/â/A/g;
		#$day_in =~ s/é/E/g;
		my $annonce = "$fulldate";
		#my $txttitle1= (`cat "$tempmsg1"\|sed -n \'1p\'\|sed -n \'s\/é\/e\/g\;s\/\[à\|â\]\/a\/g\;p\'`);
		my $txttitle1= (`cat "$tempmsg1"\|sed -n \'1p\'`);
		my $txtANNONCE = (`cat "$advisory"\|sed -n \'1p\'`);
		my $txtadvisory2 = (`cat "$advisory"\|sed -n \'2p\'`);
		my $txtfield2 = (`cat "$advisory"\|sed -n \'3\,7p\'`);
		my $txtwarning2 = (`cat "$advisory"\|sed -n \'8p\'`);
		## controle reach date (rapport<>mf)
		$reach_date = (`echo \"$txtadvisory2\"|cut -d \' \' -f1-4 |grep -w \"$month_in\"`); #`grep -o \"$jour\"`
		$reach_day = (`echo \"$reach_date\"|grep -o \"[0-9]*\"`);
		#print $reach_day;
		my $messagetext = (`cat -n "$advisory"|awk \'\{print \$1\}\'\|sed -n \'\$p\'`);
		if ($reach_day) {
			if (($jour == $reach_day) or ($jour == ($reach_day + 1))) {
				$txttitle2="ACTUELLEMENT SUR LE BASSIN";
			}
			elsif ($jour gt ($reach_day + 1) ) {
				if ($messagetext ge '5'){
					$txttitle2="AUCUNE ACTIVITÉ NOTABLE";
					$txtadvisory2 = "LE BULLETIN DU $log_date EST ARCHIVÉ";
					$txtadvisory2 =~ s/\n//; $txtadvisory2 =~ s/$/\n/;
					$txtwarning2 = "$storm INACTIF";
					$txtwarning2 =~ s/\n//;
				}
				else {
					$txttitle2 = "PAS D'ACTIVITÉ NOTABLE\nDEPUIS LE $log_date";
					$txtwarning2 = "";
				}
			}
		}
		else {
					$txttitle2 = "UN PROBLÈME EST SURVENUE";
					$txtwarning2 = "LES MESSAGES N'ONT OU ETRE LU";
		}

		if($messagetext gt '0'){
			$label0 = "<span size='10000'>$annonce</span>";
			$label1 = "\n<span foreground='yellow' weight='bold' size='small'>$txttitle2</span>\n";
			$label2 = "\n<span foreground='orange' size='small'>$txtadvisory2</span>";
			$label3 = "\n<span size='small'>$txtfield2</span>";
			$label4 = "<span foreground='green' size='small'>$txtwarning2</span>";
			if ($txtwarning2 ne ""){
				$mark = "$label0$label1$label2$label3$label4";
			}
			else {
				$mark = "$label0$label1$label2$label3";
			}
		}
		my $messagelabel = Gtk2::Label->new();
		$messagelabel->set_size_request(180,200);
		$messagelabel->set_markup("$mark");
		$messageframe->add($messagelabel);

	}
	sub msgbox4 {

		$month_in = "\U$moistext";
		#$day_in = "\U$jour";
		#$day_in = $jour;
		#print $log_date;
		my $annonce = "$fulldate";
		#my $txtANNONCE = (`cat "$advisory"\|sed -n \'1p\'`);
		$messagetext = (`cat -n "$advisory"|awk \'\{print \$1\}\'\|sed -n \'\$p\'`);
		$TXTTITLE= (`cat "$tempmsg1"\|sed -n \'1p\'`);
		$TXTADVISORY = (`cat "$advisory"\|sed -n \'2p\'`);
		$TXTFIELD = (`cat "$advisory"\|sed -n \'3\,7p\'`);
		$TXTWARNS = (`cat "$advisory"\|sed -n \'8p\'`);
		if ($TXTFIELD ne ""){
			$TXTFIELD =~ s/\n/,/g;	$TXTFIELD =~ s/,/<BR>/g;
		}

		&time_reader;
		if($messagetext gt '5'){
			&headers;
			&content;
			&image_frame;
			&bottom;
		}
		else {
			&headers;
			&content;
			&bottom;
			$TXTTITLE = "PAS D'ACTIVITÉ";
			$TXTFIELD = "PAS DE MESSAGE";
			$TXTWARNS = "";
			$TXTADVISORY= "";
		}
		$mark = "$hd0$hd1$hd2$label1$hd3$label2$label3$label4$btm0$btm1$embed$btm2";
		`echo -e "$mark" > $tmp`;
		$PAGE = "file:$tmp";
		&activate_uri;
		sub headers {
			$hd0 = '<!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.0 Transitional//EN\\">\n<HTML>\n<HEAD>\n';
			$hd1 = '<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html ; charset=utf-8\">\n</HEAD>\n<BODY LANG=\"fr-FR\" BGCOLOR=\"#333333\" DIR=\"LTR\">\n';
			$hd2 = '<DIV ID=\"Section1\" DIR="LTR">\n<TABLE WIDTH=100% BORDER=1 CELLPADDING=4 CELLSPACING=3 STYLE=\"page-break-before: always; page-break-inside: avoid\">\n';
			$hd3 = '<TR>\n<TD VALIGN=TOP WIDTH=50%>\n';
		}
		sub content {
			$report = "Rapport du $short à $actual_time h ($utat h utc)<BR>";
			$ORIGINE = "POINT D'ORIGINE DE DISTANCE: $point";
			$reach_date = (`echo \"$TXTADVISORY\"|cut -d \' \' -f1-4 |grep -w \"$month_in\"`); #`grep -o \"$jour\"`
			$reach_day = (`echo \"$reach_date\"|grep -o \"[0-9]*\"`);
			if (($jour == $reach_day) or ($jour == ($reach_day +1))) {
				$TXTTITLE = "$report Activité présente sur le bassin<BR>";
			}
			elsif ($jour gt ($reach_day + 1) ) {
			$TXTTITLE ="$report Pas d'activité depuis le bulletin du $log_date<BR>";
			$TXTWARNS = "$storm est inactif et ses bulletins ont été archivés.";
			}
			else {
			$TXTTITLE = "$report Pas d'activité sur le bassin<BR>";
			$TXTWARNS = "Ce bulletin d'activité est archivé";
			}
			$label1 = "<P ALIGN=CENTER><FONT COLOR=\'#ffff00\' FACE=\'Nimbus Sans L, sans-serif\' SIZE=3><B>$TXTTITLE</B></FONT>\n</P>\n";
			$label2 = "<P><FONT COLOR=\'#ff950e\' FACE=\'Nimbus Sans L, sans-serif\' SIZE=3><B>$TXTADVISORY</B></FONT>\n</P>\n";
			$label3 = "<P><FONT COLOR=\'#ffffff\' FACE=\'Nimbus Sans L, sans-serif\' SIZE=3><B>$TXTFIELD<BR>$ORIGINE<BR></B></FONT>\n</P>\n";
			$label4 = "<P><FONT COLOR=\'#00ae00\' FACE=\'Nimbus Sans L, sans-serif\' SIZE=3><B>$TXTWARNS</B></FONT>\n</P>\n";
		}
		sub image_frame {
			my $check = "$g_svn/kml/$storm\_$jour\.kml";
			$check =~ s/\n//g;
			if ( -f $check) {
				$numberH = "\_$jour";
			}
			else {
				$numberH = "";
			}
			#$URF = "http://code.google.com/p/h-track/source/browse/kml/07-20102011.kml";
			$URF = "http://h-track.googlecode.com/files/$storm$numberH.kml";
			#$URF = "http://h-track.googlecode.com/svn/kml/$storm.kml";
			#$URF = "http://code.google.com/p/h-track/source/browse/kml/$storm.kml";
			$URF =~ s/\//%2F/g; $URF =~ s/ /%20/g;
			$IMAGE_URL= "$URF&amp;sll=$lat,$lon&amp;ie=UTF8&amp;t=k&amp;z=5";
			#$IMAGE_URL = "http:%2F%2Fh-track.googlecode.com%2Ffiles%2FBINGIZA.kml&amp;sll=-18.8,49.8&amp;sspn=15.002259,21.269531&amp;ie=UTF8&amp;ll=-18.8,49.8&amp;spn=10.4,12&amp;t=k&amp;z=5";
			#$labelD = "<iframe width=\'500\' height=\'350\' frameborder=\'0\' scrolling=\'no\' marginheight=\'0\' marginwidth=\'0\' src=\'http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=http:%2FF%2Fh-track.googlecode.com%2Files%2FBINGIZA.kml&amp;aq=&amp;sll=48.858193,2.289619&amp;sspn=0.007285,0.019119&amp;ie=UTF8&amp;ll=-18.8,49.8&amp;spn=10.4,12&amp;t=k&amp;z=5&amp;output=embed\'></iframe>";
			$embed = "<iframe width=\'500\' height=\'350\' frameborder=\'0\' scrolling=\'no\' marginheight=\'0\' marginwidth=\'0\' src=\'http://maps.google.fr/maps?f=q&amp;source=s_q&amp;hl=fr&amp;geocode=&amp;q=$IMAGE_URL&amp;output=embed\'></iframe>";
			#$embed = "<iframe width=\'500\' height=\'350\' frameborder=\'0\' scrolling=\'no\' marginheight=\'0\' marginwidth=\'0\' src=\'http://maps.google.fr/maps?ie=UTF8&hl=fr&msa=0&msid=$IMAGE_URL&amp;output=embed\'></iframe>";
			#$labelD = "<iframe width=\'500\' height=\'350\' frameborder=\'0\' scrolling=\'no\' marginheight=\'0\' marginwidth=\'0\' src=\'http://maps.google.fr/maps?f=q&amp;source=s_q&amp;hl=fr&amp;geocode=&amp;q=ftp:%2F%2Fmaxmedia.homeftp.org%2FUploads%2Fh-track%20kml%2FBINGIZA.kml&amp;sll=-18.8,49.8&amp;sspn=15.002259,21.269531&amp;ie=UTF8&amp;ll=-18.8,49.8&amp;spn=10.4,12&amp;t=k&amp;z=5&amp;output=embed\'></iframe>";

		}
		sub bottom {
			$TXTNEXT = "PROCHAIN BULLETIN À $next_time H ($next_u h utc)";
			#$btm0 = "</TD>\n</TR>\n<TR>\n<TD>\<P ALIGN=CENTER><FONT COLOR=\'#99ccff\' FACE=\'Nimbus Sans L, sans-serif\' SIZE=2><B>$TXTNEXT</B></FONT>\n</P>\n";
			$btm0 = "</TD>\n</TR>\n<TR>\n<TD VALIGN=TOP WIDTH=50%>\<P ALIGN=CENTER><FONT COLOR=\'#99ccff\' FACE=\'Nimbus Sans L, sans-serif\' SIZE=2><B>$TXTNEXT</B></FONT>\n</P>\n";
			$btm1 = '</TD>\n</TR>\n</TABLE>\n';
			$btm2 = '\n</BODY>\n</HTML>';
		}
	}
	sub upload_pre_ops {
		if ( $g_pass ) {
			if (! -f $kml_file) {
				&print_fatal("\n'$kml_file' introuvable. Sortie...");
			}


			my $f_summary = "$storm actual kml $short";
			my $f_file = "$g_svn/kml/$storm\_$jour\.kml";
			$f_summary =~ s/\n//g;
			$f_file =~ s/\n//g;
			$svn_copy = "cp -v -f ${kml_file} ${f_file}";
			&run_cmd($svn_copy);
			#system ("ls -l $f_file");
			#print ("A $f_summary\n, B $f_file\n, DIR $g_svn\n FILE $kml_file\n ");
		}
		else {
			$filed = "Vous avez besoin d'un mot de passe.\nContactez l'auteur pour plus de renseignements:
			${g_user}\@gmail.com";
			&msgbox2;
			return($window);
		}
	}
	sub svn_upload {
		$svn_message = "$storm actual kml $short";
		$svn_message =~ s/\n//g;
		my $check_kml = "$g_svn/kml/$storm\_$jour\.kml";
		$check_kml =~ s/\n//g;
		chdir ($g_svn) or die "$g_svn introuvable";
		#print ("SVN $check_kml\n");
		$svn_add = "svn add ${check_kml}";
		$svn_commit = "svn commit ${check_kml} --message=\"${$svn_message}\" --username \"${g_user}\" --password=\"${g_pass}\" ";
		#&run_cmd($svn_copy);
		&run_cmd($svn_add);
		&run_cmd($svn_commit);
		#exit(0);
	}
	sub archive_upload {
		$g_to_upload = "$g_svn/kml/$storm\_$jour\.kml";
		$g_to_upload =~ s/\n//g;
		if ( -f $g_to_upload) {
			$numberU = "\_$jour";
		}
		else {
			$numberU = "";
		}
		$g_upload= "$g_svn/kml/$storm$numberU\.kml";
		$g_upload =~ s/\n//g;
		#print ("UP $g_upload\n");
		$g_summary = "kml archive $short";
		$g_labels = "Type-Archive";
		###############
		$g_show_progress=1;
		$g_quiet=0;
		$g_curl_path="curl";
		$g_domain="googlecode.com";
		$g_loc="/files";
		my $curl_args=&build_curl_args();
		&run_cmd($curl_args);
		#exit(0);
		sub build_curl_args() {
			my $url="https://${g_project}.${g_domain}${g_loc}";
			if ($g_labels) {
				my $lab_arg='';
				my @a=split(',',$g_labels);
				if (scalar(@a))	{
					my $l;
					foreach $l (@a) {
					$lab_arg .= "-F label=\"${l}\" ";
					}
					$lab_arg =~ s/\s$//g;
					$g_labels="$lab_arg";
				}
				else {
					$g_labels="-F $g_labels";
				}
			}
			my $curl_args="${g_curl_path} -u \"${g_user}:${g_pass}\" -F summary=\"${g_summary}\" -F upload=\@${g_upload}";
			if ($g_labels) {
				$curl_args .=" $g_labels";
			}
			if ($g_show_progress) {
				$curl_args .=" -#";
			}
			else {
				if ($g_quiet) {
					$curl_args .=" -s";
				}
			}
			$curl_args .=" ${url}";
			return($curl_args);
		}
	}
	sub run_cmd() {
		my $cmd=shift;
		local *FD;
		open(FD,"$cmd |") or &print_fatal("Impossible de lancer $cmd");
		my @lines=(<FD>);
		my $line;
		foreach $line (@lines) {
			chomp($line);
			print "$line\n";
		}
		close(FD);
	}
	sub print_fatal {
		    my $msg = shift;
		    print "$msg\n";
		    #returm($mainbox);
		    exit(1);
	}

}
